package com.example.personalizededucationsystem.dto.dto;

import com.example.personalizededucationsystem.model.StudentAssignment;
import lombok.Getter;
import lombok.Setter;

import java.time.Instant;

@Getter
@Setter
public class StudentAssignmentSummaryDto {
    private Long assignmentId;
    private String title;
    private String className;
    private Instant deadline;
    private float score;
    private StudentAssignment.Status status;

    public static StudentAssignmentSummaryDto fromEntity(StudentAssignment sa) {
        StudentAssignmentSummaryDto dto = new StudentAssignmentSummaryDto();
        dto.setStatus(sa.getStatus());

        if (sa.getAssignment() != null) {
            dto.setAssignmentId(sa.getAssignment().getAssignmentId());
            dto.setTitle(sa.getAssignment().getTitle());
            dto.setDeadline(sa.getAssignment().getDeadline());
            if (sa.getAssignment().getMyClass() != null) {
                dto.setClassName(sa.getAssignment().getMyClass().getClassName());
            }
            if (sa.getScore() != null) {
                dto.setScore(sa.getScore());
            }
        }
        return dto;
    }

}